package com.seek.util.authcheck;

import com.seek.util.HttpRequestUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by weh on 2017/7/3.
 */
public class CollectUtils {

  private static final Logger logger = LoggerFactory.getLogger(CollectUtils.class);

  /**
   * 获取采集数据
   *
   * @param url post地址
   * @param requestJson 请求json数据
   * @param retry 重试次数，默认0
   */
  public static String getDataResponse(String url, String requestJson, int retry) {
    String result = "";
    if (retry >= 3) {
      return result;
    }

    try {
      logger.info("第{}次获取数据", retry);
      result = HttpRequestUtils.httpPost(url, requestJson);
      if (StringUtils.isEmpty(result)) {
        getDataResponse(url, requestJson, retry++);
      }
    } catch (Exception e) {
      getDataResponse(url, requestJson, retry++);
    }

    return result;
  }

}
